package com.wc.alorithm_blue_bridge._二分.管道;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/15 10:50
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3949431&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 二分 + 区间合并
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] s = new int[N], l = new int[N];
    static long[][] seg = new long[N][2];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            l[i] = sc.nextInt();
            s[i] = sc.nextInt();
        }
        long l = 1, r = (long) 2e9;
        while (l < r) {
            long mid = l + r >> 1;
            if(check(mid)) r = mid;
            else l = mid + 1;
        }
        out.println(r);
        out.flush();
    }

    static boolean check(long mid) {
        int k = 0;
        // 区间合并
        for (int i = 1; i <= n; i++) {
            if (mid >= s[i]) {
                seg[++k][0] = Math.max(1, l[i] - (mid - s[i]));
                seg[k][1] = Math.min(m, l[i] + (mid - s[i]));
            }
        }
        Arrays.sort(seg, 1, k + 1, Comparator.comparing(o -> o[0]));
        long st = 0, ed = -1;
        for (int i = 1; i <= k; i++) {
            long l = seg[i][0], r = seg[i][1];
            // 这里两个 x 和 x + 1是可以合并的, 这里是区间合并的唯一区别
            if (ed + 1 < l) st = l;
            ed = Math.max(ed, r);
        }
        return st == 1 && ed == m;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

